import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import {
  ArrayMinSize,
  IsArray,
  IsBoolean,
  IsInstance,
  IsNotEmpty,
  IsNumber,
  IsOptional,
  IsString, IsUUID,
  MaxLength
} from 'class-validator';
import { Type } from "class-transformer";

export class TargetItem {
  @IsNotEmpty()
  @ApiProperty()
  @IsUUID()
  projectUuid: string;

  @IsNotEmpty()
  @ApiProperty()
  @IsString()
  @MaxLength(200)
  name: string;

  @IsNotEmpty()
  @ApiProperty()
  @IsString()
  @MaxLength(200)
  data: string;

  @IsNotEmpty()
  @ApiProperty()
  @IsBoolean()
  default?: boolean;
}

export class PresetSegmentFreqItem {
  @IsNotEmpty()
  @ApiProperty()
  @IsString()
  @MaxLength(200)
  name: string;

  @IsNotEmpty()
  @ApiProperty()
  @IsNumber()
  start: number;

  @IsNotEmpty()
  @ApiProperty()
  @IsNumber()
  end: number;

  @IsNotEmpty()
  @ApiProperty()
  @IsUUID()
  evaluationUuid: string;

  @IsNotEmpty()
  @ApiProperty()
  @IsString()
  dataGroup: string;
}


export class GlobalConfigAdminUpdateDto {
  @IsOptional()
  @ApiPropertyOptional({
    type: [TargetItem],
  })
  @IsArray()
  @ArrayMinSize(1)
  @IsInstance(TargetItem,{each: true})
  @Type(()=>TargetItem)
  targets?: TargetItem[];

  @IsOptional()
  @ApiPropertyOptional({
    type: [PresetSegmentFreqItem],
  })
  @IsArray()
  @IsInstance(PresetSegmentFreqItem,{each: true})
  @Type(()=>PresetSegmentFreqItem)
  presetSegmentFreq?: PresetSegmentFreqItem[];

  @IsOptional()
  @ApiPropertyOptional()
  @IsString()
  @MaxLength(999999)
  sensitive?: string;
}
